<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport"
        content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <link rel="stylesheet" type="text/css" href="../css/aui.2.0.css" />
    <!-- <link rel="stylesheet" type="text/css" href="../css/aui.css" /> -->
</head>
<style>
    .aui-radio-name {
        height: 26px;
        line-height: 26px;
        margin: 8px 10px 8px -5px;
        float: left;
    }

    /*单选、多选*/
    .aui-radio {
        width: 26px;
        height: 26px;
        position: relative;
        margin: 8px 10px;
        background: #ffffff;
        border: solid 1px #dddddd;
        border-radius: 50%;
        display: table;
        float: left;
        -webkit-appearance: none;
        transition: background-color ease 0.1s;
    }
</style>

<body>
    <header class="aui-bar aui-bar-nav" style="background-color: #03a9f4;position:fixed;" id="header">
        <a class="aui-pull-left aui-btn" tapmode onclick="closeWin();">
            <span class="aui-iconfont aui-icon-left"></span>
        </a>
        <div class="aui-title" id="title">
            扫码采集
        </div>
    </header>
    <div class="aui-content aui-margin-b-15"
        style="margin-top:60px; min-height: calc(100vh - 120px); overflow-y: auto;padding-bottom:100px;">
        <ul class="aui-list aui-form-list">
            <li class="aui-list-item">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-label">当前操作人:</div>
                    <input type="text" class="aui-input" id="empName" value="" disabled style="width: 80%;" />
                    <i class="aui-btn aui-btn-info aui-input-addon aui-iconfont" onclick="takeQuitPostClick()">上岗</i>
                </div>
            </li>
            <li class="aui-list-item">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-label">条码扫描区:</div>
                    <input type="text" class="aui-input" placeholder="请扫描产品条码" id="boxnum" onclick="getIdSelector();"
                        onfocus="focusFn(this)">
                    <i class="aui-input-addon aui-iconfont aui-icon-scan " style="padding-right:10px;font-size: 1.6rem"
                        onclick="doScan();"></i>
                </div>
            </li>
        </ul>

        <div style=" height: 100%;width: 100%;margin-bottom:10px;display: none;" id="tableDiv">
            <table class="table"
                style='background-color:#F8F8F8 ;width:100%; font-size:12px;color:#03a9f4;border:solid 1px #FFFFFF;table-layout:fixed'
                id="table">
                <thead>
                    <tr>
                        <td style="width:25%;text-align:center;">产品条码</td>
                        <td style="width:20%;text-align:center;">产品名称</td>
                        <td style="width:20%;text-align:center;">下一工序</td>
                        <td style="width:20%;text-align:center;">采集时间</td>
                    </tr>

                </thead>
                <tbody id="tbodytable">

                </tbody>
            </table>
        </div>
    </div>
    <footer class="aui-bar aui-bar-tab" id="footer" style="margin-top: 20px;">
        <div style="display: none;" id="footerDiv">
            <div class="aui-btn aui-btn-info aui-btn-block" onclick="saveReportInfo()">开始
            </div>
        </div>
    </footer>
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/jquery-1.8.2.min.js"></script>
<script type="text/javascript" src="../script/public.js"></script>
<script type="text/javascript" src="../script/hammer.min.js"></script>
<script type="text/javascript" src="../script/jdate.min.js"></script>
<script type="text/javascript">

    var equipUniqueId = "";   //设备唯一号
    var workCenterCode = "";  //生产线编码
    var workCellCode = "";    //工位编码
    var opCode = "";          //工序编码
    var scancodeWeb = "";
    var teamCode = "";        //班组编码
    var teamName = "";        //班组名称
    var shiftCode = "";       //班次编码
    var shiftName = "";       //班次名称
    var proddate = "";        //生产日期
    var empName = "";  //上岗人员 信息
    var AirTightness = "";//缺陷内容下拉选
    var scanCode = "";   //
    var chkbilldetailsId = "";
    var pageParam = {};
    var flag = "";
    var scanQualifiedCode = "";   //控制扫码后合格不合格按钮显示隐藏

    var isCheckPersonnelSkill = "";//是否开启人员上岗技能校验

    var routeCode = ""
    var recordSysid = ""
    var person = ""
    var opTime = ""
    // 获取光标所在组件的id
    function getIdSelector() {
        var e = event || window.event;
        var el = e.srcElement || e.target;
        idSelector = el.id;
        $("#" + el.id).select();
    }

    var uiMediaScanner = null;
    var imageFilter = null;
    var imageBrowser = null;

    //初始化查询仓库下拉框
    apiready = function () {
        // 引入多选模块
        uiMediaScanner = api.require('UIMediaScanner');
        // 引入过滤压缩模块
        imageFilter = api.require("imageFilter");
        // 引入图片浏览模块
        imageBrowser = api.require('imageBrowser');
        //获取设备唯一号
        equipUniqueId = localStorage.getItem('equipUniqueId');
        $("#boxnum").focus();
        idSelector = "boxnum";


        //1:查询产线工序信息
        searchWorkCenterData();
    }


    //扫描
    function doScan() {
        var moduleScanner = api.require('moduleScanner');
        var params = {
            top: 150, //扫描窗口的上边距
            width: 250, //扫描窗口的宽
            height: 250, //扫描窗口的高
            useColor: false, //是否使用自己设定的颜色(startColor和endColor),
            //如果不使用设定的颜色就使用默认的那张网格图
            startColor: '#0F08C8FF', //渐变起始颜色
            endColor: '#7F08C8FF', //渐变结束颜色
            animTime: 2200, //扫描动画时间,单位为毫秒
        };
        moduleScanner.toScannerActivityForResult(params, function (ret, err) {
            $("#boxnum").val(ret);
            doSearch(ret);
        });
    }

    //发货单监听回车事件
    $("#boxnum").on('keypress', function (e) {
        var keycode = e.keyCode;
        var tm = $(this).val();
        if (keycode == '13') {
            $("#boxnum").blur();
            doSearch(tm);
        }
    });

    function focusFn(ele) {
        $api.attr(ele, 'readonly', 'readonly');
        setTimeout(() => {
            $api.removeAttr(ele, 'readonly');
        }, 200);
    };


    //条码扫描
    function doSearch(tm) {
        if (opCode == null || opCode == "" || opCode == undefined) {
            api.toast({
                msg: "唯一号【" + equipUniqueId + "】未配置工序信息,不允许操作",
                duration: 3000
            });
            return;
        }
        // if (empName == null || empName == "" || empName == undefined) {
        //     api.toast({
        //         msg: "未上岗,不允许操作",
        //         duration: 3000
        //     });
        //     return;
        // }
        api.showProgress({
            title: '扫码中...',
        });
        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/scanner";
        var data = {
            values: {
                equipUniqueCode: equipUniqueId,//设备唯一号
                lineCode: workCenterCode,//产线
                workCellCode: workCellCode,//工位
                scanCode: tm,//扫码条码
                opCode: opCode,//工序
                un: un,//用户
                shiftCode: shiftCode,//班次
                proddate: proddate,//日期
                empName: empName,  //上岗人员
            }
        };
        var params = new Object();
        params.url = url;
        params.dataType = 'json';
        params.method = 'post';

        ajaxForData(params, data, false, function (ret, err) {
            if (ret) {
                api.hideProgress();

                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");


                if (myobj.code == 0) {
                    if (myobj.list != null && myobj.list.length > 0) {
                        var list = []
                        list = myobj.list
                        var nextOpCode = myobj.nextOpCode
                        var html = "";
                        html += "<tr style='text-align:center;color:#0099FF;'>";
                        html += "<td style='word-wrap:break-word;word-break:break-all;'>" + list[0].produBarcode + "</td>";
                        html += "<td style='word-wrap:break-word;word-break:break-all;'>" + list[0].produMrlname + "</td>";
                        html += "<td style='word-wrap:break-word;word-break:break-all;'>" + nextOpCode + "</td>";
                        html += "<td style='word-wrap:break-word;word-break:break-all;'>" + list[0].createDate + "</td>";
                        html += "</tr>"
                        $api.html($api.byId("tbodytable"), html);
                        $("#tableDiv").css('display', 'block');

                    }

                    $("#footerDiv").css('display', 'block');
                    routeCode = myobj.routeCode
                    recordSysid = myobj.recordSysid
                    person = myobj.person
                    opTime = myobj.opTime

                    pageParam.empName = empName
                    pageParam.nextOpCode = nextOpCode
                    pageParam.scanCode = tm
                    pageParam.showList = myobj.list
                    pageParam.routeCode = routeCode
                    pageParam.recordSysid = recordSysid
                    pageParam.person = person
                    pageParam.opTime = opTime

                    if (recordSysid == null || recordSysid == undefined || recordSysid == '') {
                        $("#footerDiv").css('display', 'block');
                    } else {
                        $("#footerDiv").css('display', 'none');
                        nextComplete()
                    }
                } else {
                    $("#footerDiv").css('display', 'none');
                    $("#boxnum").val("");
                    api.setFocus({
                        inputId: 'boxnum',
                        focus: true
                    })
                    idSelector = "boxnum";
                    api.toast({
                        msg: myobj.msg,
                        duration: 6000
                    });
                }
            } else {
                api.hideProgress();
                alert("网络连接超时!")
            }
        });
    }

    function nextComplete() {
        api.openWin({
            name: "paScanBarcodeComplete",
            url: 'paScanBarcodeComplete.html',
            pageParam: pageParam,
        });
    }
    //查询产线工位信息
    function searchWorkCenterData() {
        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/getOpCodeByUniCode";
        var data = {
            values: {
                clientCode: equipUniqueId,
                un: un,
            }
        };

        var params = new Object();
        params.url = url;
        params.dataType = 'json';
        params.method = 'post';

        ajaxForData(params, data, false, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");

                if (myobj.code == 0) {

                    //标题
                    document.getElementById("title").innerHTML = myobj.opName + "扫码采集";
                    workCenterCode = myobj.workCenterCode;
                    workCellCode = myobj.workCellCode;
                    opCode = myobj.opCode;
                    barcode_type = myobj.barcode_type;
                    isCheckPersonnelSkill = myobj.isCheckPersonnelSkill;
                    AirTightness = myobj.AirTightness;
                    if (myobj.scanQualifiedCode != null) {
                        scanQualifiedCode = myobj.scanQualifiedCode;
                    }

                    if (opCode != null && opCode != "") {
                        //1:查询当前操作人员信息
                        searchDutyPersonData();


                    }

                } else {
                    api.toast({
                        msg: myobj.msg,
                        duration: 3000
                    });
                }
            } else {
                alert("网络连接超时!")
            }
        });
    }

    //查询人员信息
    function searchDutyPersonData() {
        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/getProductionAssemblyTake";
        var data = {
            values: {
                workCenterCode: workCenterCode,
                opCode: opCode,
                workCellCode: workCellCode,
                un: un,
            }
        };
        var params = new Object();
        params.url = url;
        params.dataType = 'json';
        params.method = 'post';

        ajaxForData(params, data, false, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");

                if (myobj.code == 0) {
                    empName = myobj.empName;
                    $("#empName").val(myobj.empName);

                    teamCode = myobj.teamCode;
                    teamName = myobj.teamName;
                    shiftCode = myobj.shiftCode;
                    shiftName = myobj.shiftName;
                    proddate = myobj.proddate;
                } else {

                    //清空人员信息
                    clear();
                }

                //5:构造参数
                createPageParam();
            } else {
                alert("网络连接超时!")
            }
        });
    }

    //上岗
    function takeQuitPostClick() {
        if (opCode == null || opCode == "" || opCode == undefined) {
            api.toast({
                msg: "唯一号【" + equipUniqueId + "】未配置工序信息",
                duration: 3000
            });
            return;
        }
        api.openWin({
            name: "productionSglg",
            url: 'productionSglg.html',
            pageParam: pageParam,
        });
    }


    //提交进度
    function saveReportInfo() {

        if (opCode == null || opCode == "" || opCode == undefined) {
            api.toast({
                msg: "唯一号【" + equipUniqueId + "】未配置工序信息,不允许操作",
                duration: 3000
            });
            return;
        }
        // if (empName == null || empName == "" || empName == undefined) {
        //     api.toast({
        //         msg: "未上岗,不允许操作",
        //         duration: 3000
        //     });
        //     return;
        // }
        var produBarcode = $("#boxnum").val()
        if (produBarcode == null || produBarcode == "" || produBarcode == undefined) {
            api.toast({
                msg: "产品条码【" + produBarcode + "】不允许为空",
                duration: 3000
            });
            return;
        }
        saveReport()
    }

    function saveReport() {
        var produBarcode = $("#boxnum").val()
        api.showProgress({
            title: '开始中...',
        });
        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/scannerSaveReportInfo";
        var data = {
            values: {
                equipUniqueCode: equipUniqueId,//设备唯一号
                lineCode: workCenterCode,//产线
                workCellCode: workCellCode,//工位
                scanCode: produBarcode,//扫码条码
                opCode: opCode,//工序
                un: un,//用户
                shiftCode: shiftCode,//班次
                proddate: proddate,//日期
                barcode_type: barcode_type,//条码类型（1-唯一件，2-批次件
                empName: empName,  //上岗人员
            }
        };
        var params = new Object();
        params.url = url;
        params.dataType = 'json';
        params.method = 'post';

        ajaxForData(params, data, false, function (ret, err) {
            if (ret) {
                api.hideProgress();
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");
                if (myobj.code == 0) {
                    api.toast({
                        msg: "保存成功",
                        duration: 6000
                    });
                    pageParam.recordSysid = myobj.recordSysid
                    nextComplete()
                } else {
                    api.toast({
                        msg: myobj.msg,
                        duration: 6000
                    });
                }
            } else {
                api.hideProgress();
                alert("网络连接超时!")
            }
        });
    }
    //构造传参map
    function createPageParam() {
        pageParam = {
            workCenterCode: workCenterCode,
            workCellCode: workCellCode,
            opCode: opCode,
            teamCode: teamCode,
            teamName: teamName,
            shiftCode: shiftCode,
            shiftName: shiftName,
            proddate: proddate,
            rootName: "paScanBarcode",
            name: "paScanBarcode",
            sgFlag: '0',//上岗标识：0刷卡，1勾选
            isCheckPersonnelSkill: isCheckPersonnelSkill
        }
    }

    //清空人员上岗信息
    function clear() {
        $("#empName").val("")
        teamCode = "";
        teamName = "";
        shiftCode = "";
        shiftName = "";
        proddate = "";
    }

    //查询数据
    function refresh() {

        //1:查询当前操作人员信息
        searchDutyPersonData();
        $("#boxnum").val("");
        api.setFocus({
            inputId: 'boxnum',
            focus: true
        })
        idSelector = "boxnum";
        $api.html($api.byId("tbodytable"), '');
        $("#tableDiv").css('display', 'none');
        $("#footerDiv").css('display', 'none');
    }


    //返回按钮
    function closeWin() {
        api.closeWin({});
    }
</script>

</html>